package org.example.demoarticle.pojo;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@AllArgsConstructor
@NoArgsConstructor
@Data
public class ResultByLogin {
    public int code;
    public String msg;
    public  DTOdata data;
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    static class DTOdata {
        public String token;
        public String username;
        public String usertype;
    }
    /**
     * 增删改成功响应
     * @return
     */
    public static ResultByLogin success() {
        return new ResultByLogin(1,"success",null);
    }

    /**
     * 查询成功响应
     * @param jwt,userName
     * @return
     */
    public static ResultByLogin success(String jwt,String userName) {
        DTOdata data=new DTOdata();
        data.setToken(jwt);
        data.setUsername(userName);
        if(userName.charAt(0)>='0'&&userName.charAt(0)<='9') {
            data.setUsertype("stu");
        }else {
            data.setUsertype("tch");
        }
        return new ResultByLogin(1,"操作成功",data);
    }

    /**
     * 错误响应
     * @param msg
     * @return
     */
    public static ResultByLogin error (String msg) {
        return new ResultByLogin(0,msg,null);
    }
}
